//
//  ZJNSNnfinishedTableViewCell.m
//  LovingPartyBuilding
//
//  Created by ZJ on 2017/5/3.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJNSNnfinishedTableViewCell.h"
#import "CustomLabel.h"
#import "ZJScheduleView.h"
@interface ZJNSNnfinishedTableViewCell ()
/** 图片 */
@property (nonatomic, strong) UIImageView *imageview;
/** cell类型图片 */
@property (nonatomic, strong) UIImageView *typeImageView;
/** 题目 */
@property (nonatomic, strong) UILabel *titleLabel;

/** 进度 */
@property (nonatomic, strong) ZJScheduleView *scheduleView;
/** 标注 */
@property (nonatomic, strong) UILabel *subLabel;
/** 剩余天数 */
@property (nonatomic, strong) UILabel *residueDay;
/** 分割线 */
@property (nonatomic, strong) UILabel *underline;
/** 描述文字 */
@property (nonatomic , strong) UILabel * detailInfoLabel;
/** 进度描述文字 */
@property (nonatomic , strong) UILabel * scheduleLabel;
@end

@implementation ZJNSNnfinishedTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.imageview];
        [self.contentView addSubview:self.typeImageView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.scheduleView];
        [self.contentView addSubview:self.subLabel];
        [self.contentView addSubview:self.residueDay];
        [self.contentView addSubview:self.underline];
        [self.contentView addSubview:self.detailInfoLabel];
        [self.contentView addSubview:self.scheduleLabel];
        
        self.underline.sd_layout
        .bottomSpaceToView(self.contentView, 0)
        .leftSpaceToView(self.contentView, 0)
        .rightSpaceToView(self.contentView, 0)
        .heightIs(7.5 * [UIScreen zj_screenHScale]);
        
        self.imageview.sd_layout
        .topSpaceToView(self.contentView, 12 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self.contentView, 12 * [UIScreen zj_screenWScale])
        .bottomSpaceToView(self.underline, 12 * [UIScreen zj_screenHScale])
        .widthIs(140 * [UIScreen zj_screenWScale]);
        
        self.typeImageView.sd_layout
        .centerXEqualToView(self.imageview)
        .centerYEqualToView(self.imageview)
        .widthIs(30 * [UIScreen zj_screenHScale])
        .heightIs(30 * [UIScreen zj_screenHScale]);
        
        self.subLabel.sd_layout
        .bottomEqualToView(self.imageview)
        .leftSpaceToView(self.imageview, 8.5 * [UIScreen zj_screenWScale])
        .widthIs(140 * [UIScreen zj_screenWScale])
        .heightIs([NSString heightWithTextFontSize:[UIFont subTitleTextFontSize]]);
        
        self.residueDay.sd_layout
        .bottomEqualToView(self.subLabel)
        .leftSpaceToView(self.subLabel, 0)
        .rightSpaceToView(self.contentView, 12 * [UIScreen zj_screenWScale])
        .heightRatioToView(self.subLabel, 1);
        
        self.scheduleLabel.sd_layout
        .topEqualToView(self.imageview)
        .rightEqualToView(self.residueDay)
        .widthIs(50 * [UIScreen zj_screenWScale])
        .heightIs([NSString heightWithTextFontSize:[UIFont subTitleTextFontSize]]);
        
        self.scheduleView.sd_layout
        .leftEqualToView(self.subLabel)
        .rightEqualToView(self.residueDay)
        .bottomSpaceToView(self.subLabel, 7 * [UIScreen zj_screenHScale])
        .heightIs(15 * [UIScreen zj_screenHScale]);
        
        self.titleLabel.sd_layout
        .leftEqualToView(self.scheduleView)
        .rightSpaceToView(self.contentView, 12 * [UIScreen zj_screenWScale])
        .topEqualToView(self.imageview)
        .heightIs(10);
        
        self.detailInfoLabel.sd_layout
        .leftEqualToView(self.scheduleView)
        .rightEqualToView(self.residueDay)
        .topSpaceToView(self.titleLabel , ItemHeight * 8)
        .heightIs(10);
        
    }
    return self;
}


#pragma mark - Setter
- (void)setModel:(ZJStudySpacialDetailModel *)model{
    _model = model;
    if ([model.IMAGEPHOTO_THUMBURL containsString:@"http:"]) {
        [self.imageview sd_setImageWithURL:[NSURL URLWithString:model.IMAGEPHOTO_THUMBURL] placeholderImage:PlaceholderImage];
    }else{
        [self.imageview sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASEIMAGEURL,model.IMAGEPHOTO_THUMBURL]] placeholderImage:PlaceholderImage];
    }
    self.subLabel.text = model.CATEGORY_NAMES.firstObject[@"CATEGORY_NAME"];
    self.residueDay.text = [NSString stringWithFormat:@"还剩%@天" , model.DAY];
    if ([model.PLAYPERCENTAGE isEqualToString:@""]) {
        if ([model.ISPLAYCOMPLETION integerValue] == 1) {
            model.PLAYPERCENTAGE = @"100%";
        }
        else{
            model.PLAYPERCENTAGE = @"0%";
        }
    }
    if ([model.ISPLAYCOMPLETION integerValue] == 1) {
        self.titleLabel.text = model.NAME;
        self.titleLabel.sd_layout
        .topEqualToView(self.imageview)
        .leftEqualToView(self.scheduleView)
        .rightSpaceToView(self.self.scheduleLabel, 10 * [UIScreen zj_screenWScale])
        .heightIs([NSString heightWithTextFontSize:[UIFont titleTextFontSize]]);
        [self.titleLabel updateLayout];
        self.detailInfoLabel.text = model.COMMENT;
        self.detailInfoLabel.sd_layout
        .leftEqualToView(self.scheduleView)
        .rightEqualToView(self.residueDay)
        .topSpaceToView(self.titleLabel , ItemHeight * 8)
        .heightIs([self.detailInfoLabel getSpaceLabelHeightFromSpace:0]);
        [self.detailInfoLabel updateLayout];
        self.detailInfoLabel.hidden = NO;
        self.scheduleView.hidden = YES;
        self.scheduleLabel.text = model.PLAYPERCENTAGE;
        self.scheduleLabel.hidden = NO;
    }
    else{
        self.titleLabel.text = model.NAME;
        self.scheduleView.percentage = model.PLAYPERCENTAGE;
        self.titleLabel.sd_layout
        .topEqualToView(self.imageview)
        .leftEqualToView(self.scheduleView)
        .rightSpaceToView(self.contentView, 12 * [UIScreen zj_screenWScale])
        .heightIs([self.titleLabel getSpaceLabelHeightFromSpace:5 * [UIScreen zj_screenHScale]]);
        [self.titleLabel updateLayout];
        [self.titleLabel setLabelSpace:5 * [UIScreen zj_screenHScale]];
        self.detailInfoLabel.hidden = YES;
        self.scheduleView.hidden = NO;
        self.scheduleLabel.hidden = YES;
    }
    
    
    
}

#pragma mark - Getters

- (UIImageView *)imageview{
    if (_imageview == nil){
        _imageview = [UIImageView new];
        _imageview.contentMode = UIViewContentModeScaleAspectFill;
        _imageview.clipsToBounds = YES;
        
    }
    return _imageview;
}
- (UIImageView *)typeImageView{
    if (_typeImageView == nil){
        _typeImageView = [UIImageView new];
        _typeImageView.contentMode = UIViewContentModeCenter;
        
    }
    return _typeImageView;
}

- (UILabel *)titleLabel{
    if (_titleLabel == nil){
        _titleLabel = [UILabel new];
        _titleLabel.textColor = [UIColor textBlackColor];
        _titleLabel.font = [UIFont titleTextFont];
        _titleLabel.numberOfLines = 2;
    }
    return _titleLabel;
}
- (ZJScheduleView *)scheduleView{
    if (_scheduleView == nil){
        _scheduleView = [ZJScheduleView new];
    }
    return _scheduleView;
}

- (UILabel *)subLabel{
    if (_subLabel == nil){
        _subLabel = [UILabel new];
        _subLabel.textColor = [UIColor textGrayColor];
        _subLabel.font = [UIFont subTitleTextFont];
        
    }
    return _subLabel;
}
- (UILabel *)residueDay{
    if (_residueDay == nil){
        _residueDay = [UILabel new];
        _residueDay.textColor = [UIColor textGrayColor];
        _residueDay.font = [UIFont subTitleTextFont];
        _residueDay.textAlignment = NSTextAlignmentRight;
    }
    return _residueDay;
}

- (UILabel *)underline{
    if (_underline == nil){
        _underline = [UILabel new];
        _underline.backgroundColor = [UIColor viewBGGrayColor];
    }
    return _underline;
}

- (UILabel *)detailInfoLabel{
    if (_detailInfoLabel == nil){
        _detailInfoLabel = [UILabel new];
        _detailInfoLabel.textColor = [UIColor textBlackColor];
        _detailInfoLabel.font = [UIFont subTitleTextFont];
        _detailInfoLabel.numberOfLines = 3;
        _detailInfoLabel.hidden = YES;
    }
    return _detailInfoLabel;
}

- (UILabel *)scheduleLabel{
    if (_scheduleLabel == nil){
        _scheduleLabel = [UILabel new];
        _scheduleLabel.textColor = [UIColor zj_colorWithHexString:@"f24141"];
        _scheduleLabel.font = [UIFont subTitleTextFont];
        _scheduleLabel.textAlignment = NSTextAlignmentRight;
        _scheduleLabel.hidden = YES;
    }
    return _scheduleLabel;
}

@end
